package com.example.networkprofiler;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.*;
import android.view.*;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    public void startTest(View view){
    	System.out.println("Click Starts");
    	long t1 = System.currentTimeMillis();
    	SpeedTest st = new SpeedTest("final","jin72","mark1990", 100000);
    	double[] result = st.run();
    	long t2 = System.currentTimeMillis();
    	System.out.println("Method makespan: "+(t2-t1) + "ms");
    	
    /*
    	System.gc();
    	Thread[] t = new Thread[4];
		for(int i = 0 ; i < 4 ; i++){
			//t[i] = new Thread(new SpeedTestThread("jin72","mark1990",i));
			t[i] = new Thread(new SpeedTestThreadHttp2(i));
		}
		for(int i = 0 ; i < 4 ; i++){
			t[i].start();
		}
		for(int i = 0 ; i < 4 ; i++){
			try{
				t[i].join();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		for(int i = 0 ; i < 4 ; i++){
			t[i].yield();
		}
		double[] result = new double[2];
		result[1] = (SpeedTestThreadHttp2.endData - SpeedTestThreadHttp2.startData)*8/(SpeedTestThreadHttp2.endTime - SpeedTestThreadHttp2.startTime);
		
		System.out.println(SpeedTestThreadHttp2.endTime - SpeedTestThreadHttp2.startTime +" ms" );
		System.out.println(SpeedTestThreadHttp2.endData - SpeedTestThreadHttp2.startData +" bytes" );
	
		SpeedTestThreadHttp2.count = null;
		*/
    	TextView myview1= (TextView)findViewById(R.id.ulLabelText);
    	myview1.setText("Upload: "+(int)result[0] + " kbps");
    	TextView myview2= (TextView)findViewById(R.id.dlLabelText);
    	myview2.setText("Download: "+(int)result[1] + " kbps");
    	
    	System.out.println("Click Ends");
    	
    }
}
